package sapling.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sapling.dao.RoleDao;
import sapling.model.Role;
import sapling.model.User;
import sapling.push.JiguangPush2;

/**
 * Created by Administrator on 2017/8/10.
 */
@Service
public class PushService {
    @Autowired
    RoleDao roleDao;
    @Autowired
    TreeService treeService;

    public void inform(String name,String alert){
        new Thread(new Runnable() {
            @Override
            public void run() {
                treeService.sandinfo();
                Role role=roleDao.findOneByName(name);
                for (User user:role.getUserList()) {
                    JiguangPush2.jiguangPush(user.getUsername(),alert);
                }
            }
        }).start();
       return;
    }

    public void informDie(String name,String alert){
        Role role=roleDao.findOneByName(name);
        for (User user:role.getUserList()) {
            JiguangPush2.jiguangPush(user.getUsername(),alert);
        }
        return;
    }
}
